package com.feng.educenter.controller;


import com.feng.commonutils.JwtUtils;
import com.feng.commonutils.R;
import com.feng.commonutils.vo.UcenterMemberVo;
import com.feng.educenter.entity.UcenterMember;
import com.feng.educenter.service.UcenterMemberService;
import com.feng.educenter.utils.BeanCopyUtils;
import com.feng.educenter.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author fengge
 * @since 2023-03-26
 */
@RestController
@RequestMapping("/eduucenter/ucenter")
@CrossOrigin
public class UcenterMemberController {
    @Autowired
    private UcenterMemberService ucenterMemberService;
    //登录
    @PostMapping("login")
    public R login(@RequestBody UcenterMember ucenterMember){
        //调用service方法实现登录
       return ucenterMemberService.login(ucenterMember);
    }
    //注册
    @PostMapping("register")
    public R registerUser(@RequestBody RegisterVo registerVo){
        return ucenterMemberService.registerUser(registerVo);
    }
    //根据token获取用户信息
    @GetMapping("getMemberInfo")
    public R getMemberInfo(HttpServletRequest httpServletRequest){
        //调用jwt工具类方法，根据request对象获取头信息，返回用户id
        return ucenterMemberService.getMemberInfo(httpServletRequest);
    }
    @PostMapping("/getMemberInfoById/{memberId}")
    public UcenterMemberVo GetMemberInfoById(@PathVariable String memberId){
        UcenterMember ucenterMember = ucenterMemberService.getById(memberId);
        UcenterMemberVo ucenterMemberVo = BeanCopyUtils.copyBean(ucenterMember, UcenterMemberVo.class);
        return ucenterMemberVo;
    }
    //查询某一天注册人数
    @GetMapping("countRegister/{day}")
    public Integer countRegister(@PathVariable String day){
       return ucenterMemberService.countRegister(day);
    }
}

